/**
 * Created with IntelliJ IDEA.
 * Description:删除链表中重复的元素-2
 * User: wangxin
 * Date: 2024-10-31
 * Time: 21:29
 */
 import java.util.*;


   class ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
      this.val = val;
   }
  }

public class test1 {



        public ListNode deleteDuplicates (ListNode head) {
            // write code here
            if(head == null){
                return null;
            }
            ListNode res = new ListNode(0);
            res.next = head;
            ListNode cur = res;
            while(cur.next != null && cur.next.next != null){
                if(cur.next.val == cur.next.next.val){
                    int t = cur.next.val;
                    while(cur.next != null && cur.next.val == t){
                        cur.next = cur.next.next;
                    }
                }else{
                    cur = cur.next;
                }

            }
            return res.next;
        }

}
